﻿using System;

namespace HamcoWcs.Models.PlayBacks
{
    /// <summary>
    /// JS时间戳（14位）->.Net时间
    /// </summary>
    public abstract class JSTimeParser
    {
        protected DateTime FormatJSTimeStamp(long timeSpan)
        {
            var timeStampStr = timeSpan.ToString();
            if (timeStampStr.Length == 13)
            {
                timeStampStr = timeStampStr + "0000";
            }
            else if (timeStampStr.Length == 10)
            {
                timeStampStr = timeStampStr + "0000000";
            }
            else
            {
                throw new Exception($"输入的TimeStamp异常:{timeSpan}");
            }

            try
            {
                DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long lTime = long.Parse(timeStampStr);
                TimeSpan toNow = new TimeSpan(lTime);
                return dtStart.Add(toNow);
            }
            catch (Exception)
            {
                throw new Exception($"解析JS时间戳时发生异常");
            }

        }
    }

    /// <summary>
    /// 查询回放模型
    /// </summary>
    public class PlayBackQueryModel : JSTimeParser
    {
        public long TimeStamp { get; set; }
        public string Module { get; set; }

        public DateTime FormatJSTimeStamp()
        {
            return FormatJSTimeStamp(TimeStamp);
        }
    }

    /// <summary>
    /// 设置回放时间
    /// </summary>
    public class PlayBackTimeZone
    {
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
    }

    public class PlayBackException : Exception
    {
        public PlayBackException(string message) : base(message)
        {
        }
    }


}
